<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('添加任务')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-task-add">
        <div class="form-group">
            <label class="col-sm-3 control-label" required>任务标题：</label>
            <div class="col-sm-8">
                <input class="form-control" type="text" name="taskTitle" id="taskTitle" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">完成时间：</label>
            <div class="col-sm-4">
                <input class="form-control" type="datetime-local" name="taskStartTime" id="taskStartTime" step="1">
            </div>
            <div class="col-sm-1">
                ——
            </div>
            <div class="col-sm-4">
                <input class="form-control" type="datetime-local" name="taskEndTime" id="taskEndTime" step="1">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">执行人员：</label>
            <div class="col-sm-4">
                <select class="form-control" name="deptId" id="dept_select">
                    <option th:each="dept:${depts}" th:value="${dept.deptId}" required>[[${dept.deptName}]]</option>
                </select>
            </div>
            <div class="col-sm-4">
                <select class="form-control" name="userId" id="user_select">
                    <option>请选择部门</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">紧急程度：</label>
            <div class="col-sm-8">
                <label class="radio-box"> <input type="radio" name="taskLeave" value="1"/> 普通 </label>
                <label class="radio-box"> <input type="radio" name="taskLeave" value="2"/> 紧急 </label>
                <label class="radio-box"> <input type="radio" name="taskLeave" value="3"/> 非常紧急 </label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-2 control-label" >任务内容：</label>
            <div class="col-xs-10">
                <textarea name="taskContent" maxlength="500" class="form-control" rows="3" required></textarea>
            </div>
        </div>

    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "cyq/task/task";


    $(function(){
        $("#dept_select").change(function(){
            var deptId = $("#dept_select").val();
            $("#user_select").empty();
                $.get(
                    "/cyq/task/task/selectUserByDept",
                    {
                        deptId:deptId,
                    },
                    function(data){
                        for (var i = 0; i < data.length; i++) {
                            var a = data[i];
                            $("#user_select").append('<option value=' + a.userId + '>' + a.userName + '</option>')
                        }
                    },"json"
                )
        })


    })



    $("#form-task-add").validate({
        onkeyup: false,
        rules: {
            postName: {
                remote: {
                    url: ctx + "cyq/task/task/checkTaskNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "taskTitle": function () {
                            return $.common.trim($("#taskTitle").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "taskTitle": {
                remote: "任务标题已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-task-add').serialize());
        }
    }
</script>
</body>
</html>
